package com.indusfo.spc.client.service.impl;

import com.indusfo.spc.client.mapper.ClientPalletMapper;
import com.indusfo.spc.client.service.ClientPalletService;
import com.indusfo.spc.pojo.Pallet;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenm
 * @create 2019-12-09 19:58
 */
@Service
public class ClientPalletServiceImpl implements ClientPalletService {

  @Resource
  private ClientPalletMapper clientPalletMapper;

  @Override
  public JSONObject selectList(Pallet pallet) {
    Integer pagesize = pallet.getPagesize();
    Integer pageindex = pallet.getPageindex();
    if(pagesize != null && pageindex != null) {
      pallet.setIncept(pagesize*(pageindex - 1));
    }
    List<Pallet> pallets = clientPalletMapper.selectList(pallet);
    int count = clientPalletMapper.selectCount(pallet);
    return JSONObject.oK("查询成功", pallets, count);
  }

  @Override
  public JSONObject Untying(String palletCode) {
    Pallet pallet= clientPalletMapper.selectByPallentCode(palletCode);
    if(null == pallet){
      return JSONObject.build(JSONObject.ERROR,"无此托盘信息");
    }
    clientPalletMapper.Untying(pallet.getPalletId());
    return JSONObject.oK("解绑成功");
  }
}
